package com.orangelife.mobile.hourlyEmployee.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.curry.orangelife.mobile.R;
import com.orangelife.mobile.common.activity.OrangeLifeBaseActivity;
import com.orangelife.mobile.hourlyEmployee.biz.ValuePicker;
import com.orangelife.mobile.util.StringUtil;
import com.orangelife.mobile.util.ToastHelper;

public class ServiceTimeActivity extends OrangeLifeBaseActivity implements
		OnClickListener {

	public static final String SELECTED_LEFT = "SELECTED_LEFT";
	public static final String SELECTED_RIGHT = "SELECTED_RIGHT";

	private ValuePicker vpTest;
	/** 取消、确定、提示 */
	private TextView tvCancel, tvConfirm, tvPrompt;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_service_time);
		initeView();
		findView();
		
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		ValuePicker.time = "";
		ValuePicker.hourNum = "";
		ValuePicker.isFull = "";
	}

	private void initeView() {
		vpTest = (ValuePicker) findViewById(R.id.vpTest);
		tvCancel = (TextView) findViewById(R.id.tvCancel);
		tvConfirm = (TextView) findViewById(R.id.tvConfirm);
		tvPrompt = (TextView) findViewById(R.id.tvPrompt);
	}

	private void findView() {
		vpTest.setButtonOnClickListener(this);
		tvCancel.setOnClickListener(this);
		tvConfirm.setOnClickListener(this);
		
		// set the selected view
		Intent intent = getIntent();
		String leftValue = intent.getStringExtra(SELECTED_LEFT);
		String rightValue = intent.getStringExtra(SELECTED_RIGHT);

		vpTest.setLeftValue(leftValue);
		vpTest.setRightValue(rightValue);

		vpTest.initialize();
		
		Intent data = getIntent();
		String tip = (String) data.getSerializableExtra("tip");
		
		tvPrompt.setText(tip);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.tvCancel:
			finish();
			break;
		case R.id.tvConfirm:
			if(StringUtil.isContainBlank(ValuePicker.time) || StringUtil.isContainBlank(ValuePicker.hourNum)) {
				ToastHelper.getInstance()._toast("请选择完整的服务时间");
			} else if("1".equals(ValuePicker.isFull)) {
				ToastHelper.getInstance()._toast("下单人数过多，建议另选时间");
			} else {
				Intent intent = new Intent();
				intent.putExtra("time", ValuePicker.time);
				intent.putExtra("hourNum", ValuePicker.hourNum);
				intent.setClass(ServiceTimeActivity.this, PlaceOrderActivity.class);
				setResult(16, intent);
				finish();
			}
			break;
		default:
			break;
		}
	}

}
